package top.leinx.fxnotes.pane;

/**
 * @Author : xiaolei
 * @DateTime: 2021/3/19 11:19 上午
 */

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class AnchorPaneExample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        // 创建锚定窗格对象
        AnchorPane anchorPane = new AnchorPane();

        // 创建 Label
        Label label = new Label("welcome to anchor pane");
        label.setStyle("-fx-background-color: lightblue");
        label.setLayoutX(100.0);

        // 设置 label 节点的锚定约束，4个约束全部设置
        AnchorPane.setTopAnchor(label, 10.0);
        AnchorPane.setLeftAnchor(label,10.0);
        AnchorPane.setBottomAnchor(label,10.0);
        AnchorPane.setRightAnchor(label,10.0);

        // 创建 Button
        Button button = new Button("Button");
        // 设置 button 节点的锚定约束，右和底
        AnchorPane.setRightAnchor(button, 20.0);
        AnchorPane.setBottomAnchor(button, 20.0);

        // 把两个子节点添加到 anchorPane
        anchorPane.getChildren().addAll(label, button);

        Scene scene = new Scene(anchorPane,400,300);
        primaryStage.setTitle("AnchorPane 示例");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
